package com.pingan.pastry.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.pingan.pastry.adapter.DateTypeAdapter;


import java.util.Date;

public class GsonUtil {
    /**
     * 获取gson方法，适配gson 各种数据类型
     *
     * @return
     */
    public static Gson getGson() {
        return new GsonBuilder().registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
    }

    /*public static void main(String[] args) {
        //String jsonStr = "{\"name\":\"xiao\",\"now\":\"2021-06-09 12:04:05\",\"birth\":1623169695508}";
        String jsonStr = "{\"name\":\"xiao\",\"now\":null,\"birth\":1623169695508}";
        Gson gson = getGson();
        //Gson gson = new Gson();
        Student student = gson.fromJson(jsonStr, Student.class);
        System.out.println(student.getName() + " now: " + student.getNow() + " birth: " + student.getBirth());

        System.out.println(gson.toJson(student));

    }*/


}
